package jmvm.schemes;


import java.awt.Point;
import java.util.ArrayList;

import jmvm.components.*;
import jmvm.gui.GuiLabel;
import jmvm.gui.GuiLine;
import jmvm.gui.GuiScheme;



public class Exec4 {
	
	//
	// Gornja slika
	//
	
	public static NOT NOT1;
	public static XOR XOR1;
	public static NOT NOT2;
	public static OR OR1;
	public static NOT NOT3;
	public static OR OR2;
	public static NOT NOT4;
	public static NOT NOT5;
	public static NOT NOT6;
	public static NOT NOT7;
	
	public static NOT not_brpom;
	
	//
	// Donja slika
	//
	
	public static MP MX7,MX8,MX9;
	
	////////////
	//////////// Grafika
	////////////
	
	public static GuiScheme gui;

	public static GuiScheme getGui() {
		return gui;
	}
	
	public static void gui() {

		GuiLine line; // Pomocna promenljiva
		gui = new GuiScheme("jmvm/jmvm/images/exec4.png");

		ArrayList<ArrayList<Point>> sections;
		ArrayList<Point> points;
		
		// 
		// 
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(54,12));
		points.add(new Point(203,12));
		sections.add(points);
		line=new GuiLine(sections,Exec2.PSWZ());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(150,13));
		points.add(new Point(150,34));
		points.add(new Point(159,34));
		sections.add(points);
		line=new GuiLine(sections,Exec2.PSWZ());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(196,34));
		points.add(new Point(203,34));
		sections.add(points);
		line=new GuiLine(sections,NOT1.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(55,63));
		points.add(new Point(62,63));
		sections.add(points);
		line=new GuiLine(sections,Exec2.PSWN());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(55,77));
		points.add(new Point(63,77));
		sections.add(points);
		line=new GuiLine(sections,Exec2.PSWV());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(94,70));
		points.add(new Point(203,70));
		sections.add(points);
		line=new GuiLine(sections,XOR1.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(150,71));
		points.add(new Point(150,92));
		points.add(new Point(159,92));
		sections.add(points);
		line=new GuiLine(sections,XOR1.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(103,71));
		points.add(new Point(103,121));
		points.add(new Point(114,121));
		sections.add(points);
		line=new GuiLine(sections,XOR1.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(196,92));
		points.add(new Point(203,92));
		sections.add(points);
		line=new GuiLine(sections,NOT2.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(55,136));
		points.add(new Point(114,136));
		sections.add(points);
		line=new GuiLine(sections,Exec2.PSWZ());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(55,179));
		points.add(new Point(66,179));
		sections.add(points);
		line=new GuiLine(sections,Exec2.PSWC());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(55,194));
		points.add(new Point(66,194));
		sections.add(points);
		line=new GuiLine(sections,Exec2.PSWZ());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(376,12));
		points.add(new Point(520,12));
		sections.add(points);
		line=new GuiLine(sections,Exec2.PSWC());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(467,14));
		points.add(new Point(467,34));
		points.add(new Point(476,34));
		sections.add(points);
		line=new GuiLine(sections,Exec2.PSWC());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(376,70));
		points.add(new Point(520,70));
		sections.add(points);
		line=new GuiLine(sections,Exec2.PSWV());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(467,71));
		points.add(new Point(467,92));
		points.add(new Point(477,92));
		sections.add(points);
		line=new GuiLine(sections,Exec2.PSWV());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(376,128));
		points.add(new Point(519,128));
		sections.add(points);
		line=new GuiLine(sections,Exec2.PSWN());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(467,128));
		points.add(new Point(467,150));
		points.add(new Point(475,150));
		sections.add(points);
		line=new GuiLine(sections,Exec2.PSWN());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(141,128));
		points.add(new Point(203,128));
		sections.add(points);
		line=new GuiLine(sections,OR1.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(150,128));
		points.add(new Point(150,150));
		points.add(new Point(159,150));
		sections.add(points);
		line=new GuiLine(sections,OR1.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(94,187));
		points.add(new Point(203,187));
		sections.add(points);
		line=new GuiLine(sections,OR2.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(150,188));
		points.add(new Point(150,209));
		points.add(new Point(159,209));
		sections.add(points);
		line=new GuiLine(sections,OR2.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(196,150));
		points.add(new Point(203,150));
		sections.add(points);
		line=new GuiLine(sections,NOT3.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(196,209));
		points.add(new Point(203,209));
		sections.add(points);
		line=new GuiLine(sections,NOT4.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(512,34));
		points.add(new Point(519,34));
		sections.add(points);
		line=new GuiLine(sections,NOT5.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(512,92));
		points.add(new Point(520,92));
		sections.add(points);
		line=new GuiLine(sections,NOT6.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(512,150));
		points.add(new Point(520,150));
		sections.add(points);
		line=new GuiLine(sections,NOT7.getOut(0));
		gui.addLine(line);

		//
		//
		
		// 
		// 
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(16,459));
		points.add(new Point(16,575));
		points.add(new Point(18,575));
		points.add(new Point(18,459));
		sections.add(points);
		line=new GuiLine(sections,Bus.IBUS());
		gui.addLine(line);

		//

		// 
		// 
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(18,542));
		points.add(new Point(395,542));
		points.add(new Point(395,499));
		sections.add(points);
		line=new GuiLine(sections,Bus.IBUS());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(203,541));
		points.add(new Point(203,500));
		sections.add(points);
		line=new GuiLine(sections,Bus.IBUS());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(396,542));
		points.add(new Point(508,542));
		points.add(new Point(508,399));
		sections.add(points);
		line=new GuiLine(sections,Exec2.IBUSBits.getOut(3));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(414,495));
		points.add(new Point(414,485));
		sections.add(points);
		line=new GuiLine(sections,Exec2.IBUSBits.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(395,497));
		points.add(new Point(395,484));
		sections.add(points);
		line=new GuiLine(sections,Exec2.IBUSBits.getOut(1));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(376,494));
		points.add(new Point(376,485));
		sections.add(points);
		line=new GuiLine(sections,Exec2.IBUSBits.getOut(2));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(223,495));
		points.add(new Point(223,485));
		sections.add(points);
		line=new GuiLine(sections,Exec2.IBUSBits.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(203,497));
		points.add(new Point(203,484));
		sections.add(points);
		line=new GuiLine(sections,Exec2.IBUSBits.getOut(1));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(184,495));
		points.add(new Point(184,484));
		sections.add(points);
		line=new GuiLine(sections,Exec2.IBUSBits.getOut(2));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(240,374));
		points.add(new Point(263,374));
		points.add(new Point(263,252));
		points.add(new Point(455,252));
		points.add(new Point(455,350));
		points.add(new Point(478,350));
		sections.add(points);
		line=new GuiLine(sections,MX7.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(432,374));
		points.add(new Point(478,374));
		sections.add(points);
		line=new GuiLine(sections,MX8.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(537,362));
		points.add(new Point(546,362));
		sections.add(points);
		line=new GuiLine(sections,MX9.getOut(0));
		gui.addLine(line);

		//
		//
		
		
		gui.addLabel(new GuiLabel(188, 560, Bus.IBUS()));


		
	}
	/////////////
	/////////////
	/////////////
	
	public static void init() {
		
		//
		// Gornja slika
		//
		
		NOT1 = new NOT();
		XOR1 = new XOR();
		NOT2 = new NOT();
		OR1 = new OR();
		NOT3 = new NOT();
		OR2 = new OR();
		NOT4 = new NOT();
		NOT5 = new NOT();
		NOT6 = new NOT();
		NOT7 = new NOT();
		
		//
		// Donja slika
		//
		
		MX7 = new MP(8);
		MX8 = new MP(8);
		MX9 = new MP(2);

		not_brpom = new NOT();
	}
	
	public static void connect() {
		
		//
		// Gornja slika
		//

		NOT1.setInputPin(0, Exec2.PSWZ());
		XOR1.setInputPin(0, Exec2.PSWN());
		XOR1.setInputPin(1, Exec2.PSWV());
		NOT2.setInputPin(0, XOR1.getOut(0));
		OR1.setInputPin(0, XOR1.getOut(0));
		OR1.setInputPin(1, Exec2.PSWZ());
		NOT3.setInputPin(0, OR1.getOut(0));
		OR2.setInputPin(0, Exec2.PSWC());
		OR2.setInputPin(1, Exec2.PSWZ());
		NOT4.setInputPin(0, OR2.getOut(0));
		NOT5.setInputPin(0, Exec2.PSWC());
		NOT6.setInputPin(0, Exec2.PSWV());
		NOT7.setInputPin(0, Exec2.PSWN());
		
		//
		// Donja slika
		//

		MX7.setInputPin(0, Exec2.PSWZ());
		MX7.setInputPin(1, NOT1.getOut(0));
		MX7.setInputPin(2, Exec2.PSWN());
		MX7.setInputPin(3, NOT7.getOut(0));
		MX7.setInputPin(4, Exec2.PSWV());
		MX7.setInputPin(5, NOT6.getOut(0));
		MX7.setInputPin(6, Exec2.PSWC());
		MX7.setInputPin(7, NOT5.getOut(0));
		MX7.setCtrl(0, Exec2.IBUSBits.getOut(0));
		MX7.setCtrl(1, Exec2.IBUSBits.getOut(1));
		MX7.setCtrl(2, Exec2.IBUSBits.getOut(2));
		
		MX8.setInputPin(0, NOT3.getOut(0));
		MX8.setInputPin(1, NOT2.getOut(0));
		MX8.setInputPin(2, XOR1.getOut(0));
		MX8.setInputPin(3, OR1.getOut(0));
		MX8.setInputPin(4, NOT4.getOut(0));
		MX8.setInputPin(5, NOT5.getOut(0));
		MX8.setInputPin(6, Exec2.PSWC());
		MX8.setInputPin(7, OR2.getOut(0));
		MX8.setCtrl(0, Exec2.IBUSBits.getOut(0));
		MX8.setCtrl(1, Exec2.IBUSBits.getOut(1));
		MX8.setCtrl(2, Exec2.IBUSBits.getOut(2));
		
		MX9.setInputPin(0, MX7.getOut(0));				// OBRATI PAZNJU ----> NIJE KAO NA JOCINOJ SLICI
		MX9.setInputPin(1, MX8.getOut(0));
		MX9.setCtrl(0, Exec2.IBUSBits.getOut(3));
		
		not_brpom.setInputPin(0, MX9.getOut(0));

	}
	
	public static Pin brpom() {
		return MX9.getOut(0);
	}
	
	public static Pin not_brpom() {
		return not_brpom.getOut(0);
	}

}
